package server

import "net/http"

type HttpServlet struct {
	Name string
}

// TODO 如何能够把请求的参数直接封装到方法定义的结构体中？没有想到方法 2023.01.06
func (h *HttpServlet) RouteWithVo(pattern string, handlerFunc func(req RequestBody)) {
	http.HandleFunc(pattern, func(writer http.ResponseWriter, request *http.Request) {

	})
}

func (h *HttpServlet) RouteWithContext(pattern string, handlerFunc func(c *HttpContext)) {
	//这里的思路是: 将http处理封装在框架中，使用者关心业务处理。关于context的创建应该由server框架来做。
	http.HandleFunc(pattern, func(writer http.ResponseWriter, request *http.Request) {
		context := HttpContextFactory(writer, request)
		handlerFunc(context)
	})
}

// Route 结构体HttpServlet 对接口Server的实现
func (h *HttpServlet) Route(pattern string, handler http.HandlerFunc) {
	http.HandleFunc(pattern, handler)
}

// Start 结构体HttpServlet 对接口Server的实现
func (h *HttpServlet) Start(port string) error {
	return http.ListenAndServe(port, nil)
}
